package cn.tedu.boyou.acticle.service.impl;

import cn.tedu.boyou.acticle.domain.StrategyCommend;
import cn.tedu.boyou.acticle.mapper.StrategyCommendMapper;
import cn.tedu.boyou.acticle.service.IStrategyCommendService;
import cn.tedu.boyou.common.query.StrategyCommendQuery;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class StrategyCommendServiceImpl implements IStrategyCommendService{

    @Autowired
    private StrategyCommendMapper strategyCommendMapper;
    public PageInfo query(StrategyCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<StrategyCommend> list =  strategyCommendMapper.selectForList();
        return new PageInfo<>(list);
    }

    public void saveOrUpdate(StrategyCommend strategyCommend) {
        if(strategyCommend.getId()!= null){
            strategyCommendMapper.updateByPrimaryKey(strategyCommend);
        }else{
            strategyCommendMapper.insert(strategyCommend);
        }
    }

    public List<StrategyCommend> getCommendsByTop5() {
        return strategyCommendMapper.selectCommendsByTop5();
    }

}
